package org.jash.shop2201.goods

import android.content.Context
import android.os.Bundle
import android.widget.ImageView
import android.widget.Toast
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.bumptech.glide.Glide
import com.youth.banner.loader.ImageLoader
import org.jash.shop2201.R
import org.jash.shop2201.databinding.ActivityDetailBinding
import org.jash.shop2201.entity.Goods
import org.jash.shop2201.mvvm.BaseActivity
@Route(path = "/shop/detail")
class DetailActivity : BaseActivity<ActivityDetailBinding, DetailViewModel>() {
    @Autowired
    @JvmField
    var id = 0
    lateinit var goods: Goods
    override fun initData() {
        ARouter.getInstance().inject(this)
        viewModel.goodsLiveData.observe(this) {
            binding.goods = it
            goods = it
//            binding.banner.update(it.bannerList)
        }
        viewModel.addCartLiveData.observe(this) {
            Toast.makeText(this, it, Toast.LENGTH_SHORT).show()
        }
        viewModel.loadDetail(id)
    }

    override fun initView() {
//        binding.banner.setImageLoader(object : ImageLoader() {
//            override fun displayImage(context: Context?, path: Any?, imageView: ImageView?) {
//                imageView?.let {
//                    Glide.with(it)
//                        .load(path)
//                        .into(it)
//                }
//            }
//        })
        setSupportActionBar(binding.toolbar)
        supportActionBar?.setDisplayHomeAsUpEnabled(true)
        binding.addCart.setOnClickListener {
            viewModel.addCart(id)
        }
        binding.buy.setOnClickListener {
            ARouter.getInstance().build("/shop/pay")
                .withFloat("total", goods.goods_default_price)
                .withString("body", "${goods.goods_desc} x 1")
                .navigation()
        }
    }

}